clear all
cd "J:\workdata\706727\Temp"
use extradata 

foreach var in cash_unemp2  disab sick sometrans sueduc {
qui sum year if !mi(`var') 
replace `var'=0 if mi(`var') & inrange(year,r(min),r(max))

cap drop D`var'
gen byte D`var'=(`var'>0 & !mi(`var')) if inrange(year,r(min),r(max))
}

egen Dcash_any=rowmax(cash_unemp2 cash_unemp cash_int intyd cash_dagexp educhelp)
egen Ddisab_any=rowmax(ledyd forre re flexjob skaane resf jobafk disab )
egen Dallnonparleave=rowmax(sick disab cash_unemp2 cash_unemp cash_int educhelp dagp_unemp dagp_act ledyd forre re flexjob skaane intyd cash_dagexp resf jobafk)

gen year2=year if inrange(month,4,12)
replace year2=year-1 if inrange(month,1,3)


keep pnr year2  Dcash_unemp2 Ddisab Dsick Dsometrans Dsueduc Dcash_any Ddisab_any Dallnonparleave
collapse (max) Dcash_unemp2 Ddisab Dsick Dsometrans Dsueduc Dcash_any Ddisab_any Dallnonparleave, by(pnr year2) fast
 
rename year2 year
drop if mi(year)

drop if year==2014


save J:\Workdata\706727\Temp\LaborCollapse , replace